package com.ljn.facade.imp;

import com.ljn.core.dto.Project;
import com.ljn.core.dto.common.Page;
import com.ljn.core.dto.common.Response;
import com.ljn.core.dto.common.command.projectcommand.QueryProCommand;
import com.ljn.facade.AdminFacade;
import com.ljn.service.AdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * Created by liujunnan on 2017/11/16.
 */
@Named
public class AdminFacadeImpl implements AdminFacade {

    transient static final Logger LOGGER = LoggerFactory.getLogger(UserFacedeImpl.class);

    @Inject
    AdminService adminService;


    @Override
    public Response show(QueryProCommand queryProCommand) {
        Response response = new Response();
        try {
            Page<Project> project = adminService.show(queryProCommand);
            if (project != null) {
                response.setCode(Response.CodeEnum.SUCCESS.code);
                response.setMsg("显示所有待审核的项目");
                response.setData(project.getDatas());
            } else {
                response.setCode(Response.CodeEnum.FAILED.code);
                response.setMsg("显示失败");
                response.setData(null);
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            response.setCode(Response.CodeEnum.UNKNOWN.code);
            response.setMsg(e.getMessage());
            return response;
        }

        return response;
    }

    @Override
    public Response review(QueryProCommand queryProCommand) {
        Response response = new Response();
        if(queryProCommand.getProId()!=null)
        {
            try {
                boolean result = adminService.changeStatus(queryProCommand);
                if (result) {
                    response.setCode(Response.CodeEnum.SUCCESS.code);
                    response.setMsg("审核通过");
                    response.setData(result);
                } else {
                    response.setCode(Response.CodeEnum.FAILED.code);
                    response.setMsg("审核失败");
                    response.setData(result);
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
                response.setCode(Response.CodeEnum.UNKNOWN.code);
                response.setMsg(e.getMessage());
                return response;
            }
        }
        return  response;
    }
}
